﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style_xc.css" />
    <style type="text/css">
        p {
            margin-bottom: 0.5rem;
        }

        ::-webkit-input-placeholder { /* WebKit browsers */
            color: #eaeaea;
        }

        :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
            color: #eaeaea;
        }

        ::-moz-placeholder { /* Mozilla Firefox 19+ */
            color: #eaeaea;
        }

        :-ms-input-placeholder { /* Internet Explorer 10+ */
            color: #eaeaea;
        }
    </style>
</head>
<body class="login-bg2">
    <header class="aui-bar aui-bar-nav" id="aui-header" style="background-color:rgba(0,0,0,0) !important">
        <a class="aui-btn aui-pull-left" tapmode onClick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div id="title" class="aui-title">绑定邀请码</div>
    </header>
    <!--  有验证码版本-->
    <div class="myui-from">
        <ul class="myui-from-list">
            <li class="myui-from-list-item">
         <!--        <div class="myui-code">
                    <input id="username" type="tel" minlength="11" maxlength="11" placeholder="输入手机号码" class="myui-from-code-input">
                    <button id="btn1" type="button" name="button" style="width:20%;float:left;height: 2.2rem;" class="myui-from-code-button" onclick="getCode()">获取</button>
                </div>
            </li>
            <li class="myui-from-list-item">
                <input id="share" type="tel" minlength="6" maxlength="6" placeholder="请输入验证码" class="myui-from-list-item-input">
            </li>
           <li class="myui-from-list-item">
              <input id="password" type="password" placeholder="请设置密码" class="myui-from-list-item-input">
            </li>-->
            <li class="myui-from-list-item">
              <input id="share" type="tel" minlength="6" maxlength="6" placeholder="邀请码(选填)" class="myui-from-list-item-input">
             </li>
            <li class="myui-from-list-item">
                <button id="btn2" type="button" name="button" class="myui-from-list-item-button" onclick="toReg()">确认绑定</button>
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var api_url = localStorage.getItem('api_url');
    var onoff = true;
    var code_data = '';
    var user = '';
    var pass = '';
		var share = '';
    apiready = function () {
        api.parseTapmode();
        var header = $api.byId('aui-header');
        $api.fixStatusBar(header);
        var headerPos = $api.offset(header);
        var body_h = $api.offset($api.dom('body')).h;

    }




    //去注册
    function toReg() {
     //   var username = $api.val($api.byId('username'));
     //   var password = $api.val($api.byId('password'));
           var share = $api.val($api.byId('share'));
 
     /*   if (username == '') {
    
         api.toast({
                msg: '新奇影视提醒！账号都没输入',
            });
            return;
        }*/
        //  if(password == ''){
        ///*        api.alert({
        //        title: '调皮~',
        //        msg: '请输入密码',
        //    });
        //  原弹窗提示  */
        //  api.toast({
        //       msg: '新奇影视提醒！密码还没输入',
        //  });
        //    return;
        //  }

        // if(share == ''){
        //   api.alert({
        //       title: '调皮~',
        //       msg: '密码不一致',
        //   });
        //   return;
        // }
     /*   if (username.length < 6) {
            /*  api.alert({
                  title: '出错了',
                  msg: '请输入6位数以上账号',
              });
              */

      /*      api.toast({
                msg: ' 请输入6位数以上账号 ',
            });
            return;
        }
        if (yzcode != code_data) {
            api.alert({
                title: '错误提示',
                msg: '您输入的验证码不正确',
            });
            return;
        }
        /*
          if(localStorage.getItem('reg_name') == username){
            api.alert({
                title: '错误提示',
                msg: '手机号输入不一致',
            });
            return;
          }
          */
  	  share = $api.val($api.byId('share'));

        /*
        api.showProgress({
            title: '注册中...',
            text: '请稍等...',
            modal: false
        });
  */
        api.toast({
            msg: ' 注册中 请稍等…… ',
        });

        Other_Reg();
    }

    //页面传参
 /*   function openLogin(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }


        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam:{user:user,pass:pass},
        });
    }*/

    //获取验证码
    function getCode() {
        var yzcode = $api.val($api.byId('yzcode'));
        var btn1 = $api.byId('btn1');
        var username = $api.val($api.byId('username'));
        localStorage.setItem('reg_name', username);
        if (!onoff) {
            return;
        }
        onoff = false;

        if (username == '') {
            api.alert({
                title: '警告！',
                msg: '请输入手机号码',
            });
            onoff = true;
            return;
        }
        if (username.length != 11) {
            api.alert({
                title: '警告！',
                msg: '请输入11位手机号码',
            });
            onoff = true;
            return;
        }
        code_data = RndNum(6);
        var content = escape('#code#=' + code_data);
        //alert(code_data);
        api.ajax({
            url: 'http://v.juhe.cn/sms/send?mobile=' + username + '&tpl_id=102968&tpl_value=' + content + '&key=83479e0b7b3f78c6df94e16ed01475c6',
            method: 'get'
        }, function (ret, err) {
            // if (ret) {
            //   alert( JSON.stringify( ret ) );
            // }else {
            //   alert( JSON.stringify( err ) );
            // }

            api.toast({
                msg: '发送成功',
                duration: 1000,
                location: 'middle'
            });
            var nuw = 60;
            var timer = setInterval(function () {
                nuw--;

                if (nuw < 1) {
                    btn1.innerHTML = '获取';
                    clearInterval(timer);
                    onoff = true;
                } else {
                    btn1.innerHTML = nuw + 's';
                }


            }, 1000)
        });


    }

    //生成验证码
    function RndNum(n) {
        var rnd = "";
        for (var i = 0; i < n; i++)
            rnd += Math.floor(Math.random() * 10);
        return rnd;
    }


    function closeWin() {
        api.closeWin({
        });
    }

    function openWin(name) {
        var delay = 0;
        if (api.systemType != 'ios') {
            delay = 300;
        }
        api.openWin({
            name: '' + name + '',
            url: '' + name + '.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false
        });
    }

			function Other_Reg() {
			var Other_type = '微信';
			var user = localStorage.getItem('Other_openid');
			var pass = localStorage.getItem('Other_openid');
			  var share = $api.val($api.byId('share'));
			api.ajax({
				url: 'http://hjhkjk.xyz/login/login/createhmyx.html',
				method: 'get',
				data: {
					values: {
						name: user,
						password: pass,
						share_ma: share,
						type: Other_type + '@' + localStorage.getItem('Other_name')
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 0) {
						if(ret.cun == 1) { //当前用户已存在
							api.showProgress({
								title: Other_type + '登录中...',
								text: '请稍等...',
								modal: false
							});
							api.ajax({
								url: 'http://hjhkjk.xyz/login/login/veifys.html',
								method: 'get',
								data: {
									values: {
										username: localStorage.getItem('Other_openid'),
										passwd: localStorage.getItem('Other_openid'),
										imei: api.deviceId
									}
								}
							}, function(ret, err) {
								if(ret) {
									if(ret.code == 0) {
										api.hideProgress();
										alert('账号或密码不正确');
										return;
									} else if(ret.code == 1) {
										if(ret.msg['status'] && ret.msg['status'] != 1 ){
												api.toast({
													msg: '(ｷ｀ﾟДﾟ´)!! 账号被禁用！',
													duration: 5000
												});

												//alert( JSON.stringify( err ) );
												return;
											}
										localStorage.setItem('accountLogin',1);
										localStorage.setItem('user_id', ret.msg['id']);
										localStorage.setItem('user_name', user);
										localStorage.setItem('password', pass);
										localStorage.setItem('user_time', ret.msg['time']);
										localStorage.setItem('user_share', ret.msg['share']);
										localStorage.setItem('user_advert', ret.msg['advert']);
										localStorage.setItem('user_code', ret.msg['code']);
										localStorage.setItem('user_weichat', ret.msg['weichat']);
										localStorage.setItem('power', ret.msg['power']);
										localStorage.setItem('url', ret.msg['url']);
										localStorage.setItem('url1', ret.msg['url1']);
										localStorage.setItem('url2', ret.msg['url2']);
										localStorage.setItem('url3', ret.msg['url3']);
										localStorage.setItem('url4', ret.msg['url4']);
										localStorage.setItem('imei', api.deviceId);
										localStorage.setItem('user_nickname', ret.msg['nick_name']);
										localStorage.setItem('user_jinb', ret.msg['share']);
										localStorage.setItem('tud', ret.msg['tudi']);
										localStorage.setItem('tjryqma',ret.msg['sjyqma']);
			                        	localStorage.setItem('stdejb',ret.msg['stjb']);										
										localStorage.setItem('user_zfb',ret.msg['zfb']);
										localStorage.setItem('user_weichat', ret.msg['weichat']);
										localStorage.setItem('user_sharema',ret.msg['share_ma']);

										api.sendEvent({
											name: 'newLoingdata',
											extra: {}
										});
										api.hideProgress();
										api.closeWin();
									}
								} else {
									api.hideProgress();
									alert('网络错误！');
									//alert( JSON.stringify( err ) );
									return;
								}
							});
						} else {
							api.hideProgress();
							api.alert({
								title: '错误~',
								msg: ret.msg,
							});
						}

					} else {
						denglu()
					}
				} else {
					api.hideProgress();
					api.alert({
						title: '糟糕~',
						msg: '网络错误！',
					});
				}
			});
		}
		//注册并登录
		function denglu() {
			localStorage.setItem('accountLogin',1);
			var user = localStorage.getItem('Other_openid');
			var pass = localStorage.getItem('Other_openid');
			api.showProgress({
				title: '注册成功...',
				text: '登录中请稍等...',
				modal: false
			});
			api.ajax({
				url: 'http://hjhkjk.xyz/login/login/veifys.html',
				method: 'get',
				data: {
					values: {
						username: user,
						passwd: pass,
						imei: api.deviceId
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 0) {
						api.hideProgress();
						alert('账号或密码不正确');
						return;
					} else if(ret.code == 1) {
						//alert( JSON.stringify( ret ) );
						localStorage.setItem('user_id', ret.msg['id']);
						localStorage.setItem('user_name', user);
						localStorage.setItem('password', pass);
						localStorage.setItem('user_time', ret.msg['time']);
						localStorage.setItem('user_share', ret.msg['share']);
						localStorage.setItem('user_advert', ret.msg['advert']);
						localStorage.setItem('user_code', ret.msg['code']);
						localStorage.setItem('power', ret.msg['power']);
						localStorage.setItem('url', ret.msg['url']);
						localStorage.setItem('url1', ret.msg['url1']);
						localStorage.setItem('url2', ret.msg['url2']);
						localStorage.setItem('url3', ret.msg['url3']);
						localStorage.setItem('url4', ret.msg['url4']);
						localStorage.setItem('imei', api.deviceId);
						localStorage.setItem('user_nickname', ret.msg['nick_name']);
						localStorage.setItem('user_jinb', ret.msg['share']);
						localStorage.setItem('tud', ret.msg['tudi']);
						localStorage.setItem('tjryqma',ret.msg['sjyqma']);
			          	localStorage.setItem('stdejb',ret.msg['stjb']);						
                        localStorage.setItem('user_zfb',ret.msg['zfb']);
                        localStorage.setItem('user_weichat', ret.msg['weichat']);
						localStorage.setItem('user_sharema',ret.msg['share_ma']);
						api.sendEvent({
							name: 'newLoingdata',
							extra: {}
						});
						api.hideProgress();
								 api.openWin({
						    name: 'index',
						    url: '../index.html',
						});
					//	 openWin('openLogin');
						api.closeWin();
					}
				} else {
					api.hideProgress();
					alert('网络错误！');
					return;
				}
			});
		}
  /*  function Other_Reg(mobile) {
        var Other_type = '微信';
        var user = localStorage.getItem('Other_openid');
        var pass = localStorage.getItem('Other_openid');
		  var share = $api.val($api.byId('share'));
        api.ajax({
            url: 'http://hjhkjk.xyz/login/login/createhmyx.html',
            method: 'get',
            data: {
                values: {
                    name: user,
                    password: pass,
                    share_ma: share,
                    type: Other_type + '@' + localStorage.getItem('Other_name')
                }
            }
        }, function (ret, err) {
            if (ret) {
                if (ret.code == 0) {
                    if (ret.cun == 1) { //当前用户已存在
                        api.showProgress({
                            title: Other_type + '登录中...',
                            text: '请稍等...',
                            modal: false
                        });
                        api.ajax({
                            url: 'http://hjhkjk.xyz/login/login/veifys.html',
                            method: 'get',
                            data: {
                                values: {
                                    username: localStorage.getItem('Other_openid'),
                                    passwd: localStorage.getItem('Other_openid'),
                                    imei: api.deviceId
                                }
                            }
                        }, function (ret, err) {
                            if (ret) {
                                if (ret.code == 0) {
                                    api.hideProgress();
                                    alert('账号或密码不正确');
                                    return;
                                } else if (ret.code == 1) {
                                    if (ret.msg['status'] && ret.msg['status'] != 1) {
                                        api.toast({
                                            msg: '(ｷ｀ﾟДﾟ´)!! 账号被禁用！',
                                            duration: 5000
                                        });

                                        //alert( JSON.stringify( err ) );
                                        return;
                                    }
                                    localStorage.setItem('accountLogin', 1);
                                    localStorage.setItem('user_id', ret.msg['id']);
                                    localStorage.setItem('user_name', user);
                                    localStorage.setItem('password', pass);
                                    localStorage.setItem('user_time', ret.msg['time']);
                                    localStorage.setItem('user_share', ret.msg['share']);
                                    localStorage.setItem('user_advert', ret.msg['advert']);
                                    localStorage.setItem('user_code', ret.msg['code']);
                                    localStorage.setItem('user_weichat', ret.msg['weichat']);
                                    localStorage.setItem('power', ret.msg['power']);
                                    localStorage.setItem('url', ret.msg['url']);
                                    localStorage.setItem('url1', ret.msg['url1']);
                                    localStorage.setItem('url2', ret.msg['url2']);
                                    localStorage.setItem('url3', ret.msg['url3']);
                                    localStorage.setItem('url4', ret.msg['url4']);
                                    localStorage.setItem('imei', api.deviceId);
                                    localStorage.setItem('user_nickname', ret.msg['nick_name']);
                                    localStorage.setItem('user_jinb', ret.msg['share']);
                                    localStorage.setItem('tud', ret.msg['tudi']);
                                    localStorage.setItem('tjryqma', ret.msg['sjyqma']);
			                     	localStorage.setItem('stdejb',ret.msg['stjb']);                                   
                                    localStorage.setItem('user_zfb', ret.msg['zfb']);
                                    localStorage.setItem('user_weichat', ret.msg['weichat']);
                                    localStorage.setItem('user_sharema', ret.msg['share_ma']);

                                    api.sendEvent({
                                        name: 'newLoingdata',
                                        extra: {}
                                    });
                                    api.hideProgress();
                                    api.closeWin();


                                }
                            } else {
                                api.hideProgress();
                                alert('网络错误！');
                                //alert( JSON.stringify( err ) );
                                return;
                            }
                        });
                    } else {
                        api.hideProgress();
                        api.alert({
                            title: '错误~',
                            msg: ret.msg,
                        });
                    }

                } else {
                    denglu()
                }
            } else {
                api.hideProgress();
                api.alert({
                    title: '糟糕~',
                    msg: '网络错误！',
                });
            }
        });
    }
    //注册并登录
    function denglu() {
        localStorage.setItem('accountLogin', 1);
        var user = localStorage.getItem('Other_openid');
        var pass = localStorage.getItem('Other_openid');
        api.showProgress({
            title: '注册成功...',
            text: '登录中请稍等...',
            modal: false
        });
        api.ajax({
            url: 'http://hjhkjk.xyz/login/login/veifys.html',
            method: 'get',
            data: {
                values: {
                    username: user,
                    passwd: pass,
                    imei: api.deviceId
                }
            }
        }, function (ret, err) {
            if (ret) {
                if (ret.code == 0) {
                    api.hideProgress();
                    alert('账号或密码不正确');
                    return;
                } else if (ret.code == 1) {
                    //alert( JSON.stringify( ret ) );
                    localStorage.setItem('user_id', ret.msg['id']);
                    localStorage.setItem('user_name', user);
                    localStorage.setItem('password', pass);
                    localStorage.setItem('user_time', ret.msg['time']);
                    localStorage.setItem('user_share', ret.msg['share']);
                    localStorage.setItem('user_advert', ret.msg['advert']);
                    localStorage.setItem('user_code', ret.msg['code']);
                    localStorage.setItem('power', ret.msg['power']);
                    localStorage.setItem('url', ret.msg['url']);
                    localStorage.setItem('url1', ret.msg['url1']);
                    localStorage.setItem('url2', ret.msg['url2']);
                    localStorage.setItem('url3', ret.msg['url3']);
                    localStorage.setItem('url4', ret.msg['url4']);
                    localStorage.setItem('imei', api.deviceId);
                    localStorage.setItem('user_nickname', ret.msg['nick_name']);
                    localStorage.setItem('user_jinb', ret.msg['share']);
                    localStorage.setItem('tud', ret.msg['tudi']);
                    localStorage.setItem('tjryqma', ret.msg['sjyqma']);
			      	localStorage.setItem('stdejb',ret.msg['stjb']);                    
                    localStorage.setItem('user_zfb', ret.msg['zfb']);
                    localStorage.setItem('user_weichat', ret.msg['weichat']);
                    localStorage.setItem('user_sharema', ret.msg['share_ma']);
                    api.sendEvent({
                        name: 'newLoingdata',
                        extra: {}
                    });
                    api.hideProgress();
				//	openWin('frame4');
                    api.closeWin();
                }
            } else {
                api.hideProgress();
                alert('网络错误！');
                return;
            }
        });
    }*/
</script>
</html>
